﻿using LeisureNcre.Helper;
using System;
using System.Configuration;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace LeisureNcre
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Mutex mtx = null;
            //预防程序启动多个
            bool newMutexCreated = true;
            try
            {
                mtx = new Mutex(true, Assembly.GetExecutingAssembly().FullName, out newMutexCreated);
                if (!newMutexCreated)
                {
                    LogHelper.Info("程序已启动！");
                    MessageBox.Show("程序已启动！");
                    Environment.Exit(0);
                }
                else
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    String needUpdate = ConfigurationManager.AppSettings["ServerIP"];
                    string serverIP = ConfigurationManager.AppSettings["ServerIP"];
                    int serverPort = int.Parse(ConfigurationManager.AppSettings["ServerPort"]);
                    string callBackExeName = ConfigurationManager.AppSettings["CallbackExeName"];
                    string title = ConfigurationManager.AppSettings["Title"];
                    int VersionCode = int.Parse(ConfigurationManager.AppSettings["Version"]);

                    UpdateFrm form = new UpdateFrm(serverIP, serverPort, callBackExeName, title, VersionCode);

                    Application.Run(form);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}
